package com.inspur

import org.apache.spark.sql.SparkSession

case class Product(Id:String, style01:String, shopid:String, style02:String)

object PortraitSaler2 { // 计算商户画像 spark SQL 实现

  def main(args: Array[String]): Unit = {
    val sess = SparkSession.builder()
      .appName("PortraitSaler2")
      .master("local")
      .getOrCreate()

    import sess.implicits._

    val products = sess.read.textFile("hdfs://192.168.66.88:8020/0616/clear_data/products/part-00000")
      .map(_.split("\t"))
      .map(element => Product(element(0), element(1),element(2),element(3)))

    products.createOrReplaceTempView("products")
    sess.sql("select shopid,concat_ws('--',collect_set(style01)) as style " +
      "from products group by shopid")
//      .show(100,false)
      .repartition(1)
      .write.csv("hdfs://192.168.66.88:8020/0616/portrait_sparkSQL")
  }

}
